package prototype;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.*;

/**
 * Created by liuweijie on 2018/4/24.
 */
public class Printer extends OfficeTool implements Cloneable, Serializable {

    private PageBean page;

    public Printer() {
        page = new PageBean();
        this.setName("惠普打印机");
        this.setPrice(3000);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oss = null;
        ByteArrayInputStream bis = null;
        ObjectInputStream ois = null;
        Printer CopyPrinter = null;
        // 序列化
        try {
            bos = new ByteArrayOutputStream();
            oss = new ObjectOutputStream(bos);
            oss.writeObject(this);
            // 反序列化

            bis = new ByteArrayInputStream(bos.toByteArray());
            ois = new ObjectInputStream(bis);
            CopyPrinter = (Printer) ois.readObject();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bos.close();
                oss.close();
                bis.close();
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return CopyPrinter;
    }

    public PageBean getPage() {
        return page;
    }

    public void setPage(PageBean page) {
        this.page = page;
    }
}
